<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>Hello mdui</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
        <script type="text/javascript" src="../../statics/common/js/header.js"></script>
		<link rel="stylesheet" href="../../statics/mdui/css/mdui.min.css">
	</head>

	<body>
		<header class="mdui-bar mdui-bar-nav">
			<a id="back" class="mdui-action-back mdui-icon mdui-icon-left-nav mdui-pull-left"></a>
			<h1 id="title" class="mdui-title">下拉刷新和上拉加载更多</h1>
		</header>
		<!--下拉刷新容器-->
		<div id="pullrefresh" class="mdui-content mdui-scroll-wrapper">
			<div class="mdui-scroll">
				<!--数据列表-->
				<ul class="mdui-table-view mdui-table-view-chevron">
					
				</ul>
			</div>
		</div>
		<script src="../../statics/mdui/js/mdui.min.js"></script>
		<script>
			mdui.init({
				pullRefresh: {
					container: '#pullrefresh',
					down: {
						callback: pulldownRefresh
					},
					up: {
						contentrefresh: '正在加载...',
						callback: pullupRefresh
					}
				}
			});
			/**
			 * 下拉刷新具体业务实现
			 */
			function pulldownRefresh() {
				setTimeout(function() {
					var table = document.body.querySelector('.mdui-table-view');
					var cells = document.body.querySelectorAll('.mdui-table-view-cell');
					for (var i = cells.length, len = i + 3; i < len; i++) {
						var li = document.createElement('li');
						li.className = 'mdui-table-view-cell';
						li.innerHTML = '<a class="mdui-navigate-right">Item ' + (i + 1) + '</a>';
						//下拉刷新，新纪录插到最前面；
						table.insertBefore(li, table.firstChild);
					}
					mdui('#pullrefresh').pullRefresh().endPulldownToRefresh(); //refresh completed
				}, 1500);
			}
			var count = 0;
			/**
			 * 上拉加载具体业务实现
			 */
			function pullupRefresh() {
				setTimeout(function() {
					mdui('#pullrefresh').pullRefresh().endPullupToRefresh((++count > 2)); //参数为true代表没有更多数据了。
					var table = document.body.querySelector('.mdui-table-view');
					var cells = document.body.querySelectorAll('.mdui-table-view-cell');
					for (var i = cells.length, len = i + 20; i < len; i++) {
						var li = document.createElement('li');
						li.className = 'mdui-table-view-cell';
						li.innerHTML = '<a class="mdui-navigate-right">Item ' + (i + 1) + '</a>';
						table.appendChild(li);
					}
				}, 1500);
			}
			if (mdui.os.plus) {
				mdui.plusReady(function() {
					setTimeout(function() {
						mdui('#pullrefresh').pullRefresh().pullupLoading();
					}, 1000);

				});
			} else {
				mdui.ready(function() {
					mdui('#pullrefresh').pullRefresh().pullupLoading();
				});
			}
		</script>
	</body>

</html>